package design.patterns.creation;

/**
 * 生成器模式
 * 解释：
 * 生成器模式是一种创建型设计模式， 使你能够分步骤创建复杂对象。
 * 该模式允许你使用相同的创建代码生成不同类型和形式的对象。
 */

/**
 * 情景
 * 房屋的两面墙需要粉刷不同的颜色
 */
public class C_Builder {
    public static void main(String[] args) {
        WallColorBuilder wallColorBuilder = new WallColorBuilder();
        wallColorBuilder.setWall_1(WallColor.WHITE);
        wallColorBuilder.setWall_2(WallColor.WHITE);
        System.out.println(wallColorBuilder);

        WallColorManualBuilder wallColorManualBuilder = new WallColorManualBuilder();
        wallColorManualBuilder.setWall_1(WallColor.WHITE);
        wallColorManualBuilder.setWall_2(WallColor.WHITE);
        Manual resultFromBuilder = wallColorManualBuilder.getResult();
        System.out.println(resultFromBuilder);

        WallColorManualBuilder wallColorManualBuilderByDirector = new WallColorManualBuilder();
        Director director = new Director();
        director.constructAllBlack(wallColorManualBuilderByDirector);
        Manual result = wallColorManualBuilderByDirector.getResult();
        System.out.println(result);
    }
}


enum WallColor{
    BLACK("黑色"),
    WHITE("白色");
    private String color;

    WallColor(String color) {
        this.color = color;
    }
}
class Wall{
    private WallColor wall1_color;
    private WallColor wall2_color;

    public Wall(WallColor wall1_color, WallColor wall2_color) {
        this.wall1_color = wall1_color;
        this.wall2_color = wall2_color;
    }
}
interface Builder{
    void setWall_1(WallColor wallColor);
    void setWall_2(WallColor wallColor);
}


class WallColorBuilder implements Builder{
    private WallColor wall1_Color;
    private WallColor wall2_Color;

    @Override
    public void setWall_1(WallColor wallColor) {
        wall1_Color = wallColor;
    }

    @Override
    public void setWall_2(WallColor wallColor) {
        wall2_Color = wallColor;
    }
    public Wall getResult(){
        return new Wall(wall1_Color,wall2_Color);
    }

    @Override
    public String toString() {
        return "WallColorBuilder{" +
                "wall1_Color=" + wall1_Color +
                ", wall2_Color=" + wall2_Color +
                '}';
    }
}

class Manual {
    private WallColor wall1_Color;
    private WallColor wall2_Color;

    public Manual(WallColor wall1_Color, WallColor wall2_Color) {
        this.wall1_Color = wall1_Color;
        this.wall2_Color = wall2_Color;
    }

    @Override
    public String toString() {
        return "Manual{" +
                "wall1_Color=" + wall1_Color +
                ", wall2_Color=" + wall2_Color +
                '}';
    }
}
class WallColorManualBuilder implements Builder{
    private WallColor wall1_Color;
    private WallColor wall2_Color;

    @Override
    public void setWall_1(WallColor wallColor) {
        wall1_Color = wallColor;
    }

    @Override
    public void setWall_2(WallColor wallColor) {
        wall2_Color = wallColor;
    }

    public Manual getResult(){
        return new Manual(wall1_Color,wall2_Color);
    }

}

class Director{
    void constructAllWhite(Builder builder){
        builder.setWall_1(WallColor.WHITE);
        builder.setWall_2(WallColor.WHITE);
    }
    void constructAllBlack(Builder builder){
        builder.setWall_1(WallColor.BLACK);
        builder.setWall_2(WallColor.BLACK);
    }
}